<?php

	// TITLE: Interest AUTO MODEL
	// FILE: scaffolding/model/interest.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createInterest = function($con, $interest) {
		$sql = 'INSERT INTO interest (id, type_id, title, description) VALUES (';
		$sql .= $interest->getId() . ', ';
		$sql .= $interest->getTypeId() . ', ';
		$sql .= $interest->getTitle() . ', ';
		$sql .= $interest->getDescription() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readInterest = function($con, $id) {
		$sql = 'SELECT * FROM interest WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$interest = new Interest();
			$interest->setId(result[0]);
			$interest->setTypeId($dbio->select($readType(result[1])));
			$interest->setTitle(result[2]);
			$interest->setDescription(result[3]);
		} else {
			$interest = false;
		}
		return $interest;
	};

	$updateInterest = function($con, $interest) {
		$sql = 'UPDATE interest SET ';
		$sql .= 'id = ' . $interest->getId() . ', ';
		$sql .= 'type_id = ' . $interest->getTypeId() . ', ';
		$sql .= 'title = ' . $interest->getTitle() . ', ';
		$sql .= 'description = ' . $interest->getDescription() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteInterest = function($con, $id) {
		$sql = 'DELETE FROM interest WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listInterest = function($con) {
		$sql = 'SELECT * FROM interest';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$interests = array();
			while ($result = mysqli_fetch_array($results)) {
				$interest = new Interest();
				$interest->setId(result[0]);
				$interest->setTypeId($dbio->select($readType(result[1])));
				$interest->setTitle(result[2]);
				$interest->setDescription(result[3]);
				$interests[] = interest;
			}// end while
		} else {
			$interests = false;
		}
		return $interests;
	};

